<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>获取焦点</title>
    <script>
        function f(fun) {
            fun.style.background='red';
        }
        function f1(fun) {
            fun.style.background='green';
        }
    </script>
</head>

<body>
<input type="text"  onfocus="return f(this);" onblur="return f1(this);" style="background: green;">
<input type="password"  onfocus="return f(this);" onblur="return f1(this);" style="background: green;">
<input type="password" onfocus="return f(this);" onblur="return f1(this);" style="background: green;">
</body>
</html>